/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package reamodel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import reamodel.DecrementCommitment;
import reamodel.DecrementEconomicEvent;
import reamodel.DecrementEconomicEventType;
import reamodel.IncrementEconomicEvent;
import reamodel.Outflow;
import reamodel.ReamodelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Decrement Economic Event</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link reamodel.impl.DecrementEconomicEventImpl#getOutflow <em>Outflow</em>}</li>
 *   <li>{@link reamodel.impl.DecrementEconomicEventImpl#getDuality <em>Duality</em>}</li>
 *   <li>{@link reamodel.impl.DecrementEconomicEventImpl#getFulfill <em>Fulfill</em>}</li>
 *   <li>{@link reamodel.impl.DecrementEconomicEventImpl#getTypifiedBy <em>Typified By</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DecrementEconomicEventImpl extends EconomicEventImpl implements DecrementEconomicEvent {
	/**
	 * The cached value of the '{@link #getOutflow() <em>Outflow</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOutflow()
	 * @generated
	 * @ordered
	 */
	protected EList<Outflow> outflow;

	/**
	 * The cached value of the '{@link #getDuality() <em>Duality</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDuality()
	 * @generated
	 * @ordered
	 */
	protected EList<IncrementEconomicEvent> duality;

	/**
	 * The cached value of the '{@link #getFulfill() <em>Fulfill</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFulfill()
	 * @generated
	 * @ordered
	 */
	protected EList<DecrementCommitment> fulfill;

	/**
	 * The cached value of the '{@link #getTypifiedBy() <em>Typified By</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypifiedBy()
	 * @generated
	 * @ordered
	 */
	protected DecrementEconomicEventType typifiedBy;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DecrementEconomicEventImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ReamodelPackage.Literals.DECREMENT_ECONOMIC_EVENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Outflow> getOutflow() {
		if (outflow == null) {
			outflow = new EObjectContainmentWithInverseEList<Outflow>(Outflow.class, this, ReamodelPackage.DECREMENT_ECONOMIC_EVENT__OUTFLOW, ReamodelPackage.OUTFLOW__EVENT);
		}
		return outflow;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<IncrementEconomicEvent> getDuality() {
		if (duality == null) {
			duality = new EObjectWithInverseResolvingEList.ManyInverse<IncrementEconomicEvent>(IncrementEconomicEvent.class, this, ReamodelPackage.DECREMENT_ECONOMIC_EVENT__DUALITY, ReamodelPackage.INCREMENT_ECONOMIC_EVENT__DUALITY);
		}
		return duality;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DecrementCommitment> getFulfill() {
		if (fulfill == null) {
			fulfill = new EObjectWithInverseResolvingEList.ManyInverse<DecrementCommitment>(DecrementCommitment.class, this, ReamodelPackage.DECREMENT_ECONOMIC_EVENT__FULFILL, ReamodelPackage.DECREMENT_COMMITMENT__FULFILL);
		}
		return fulfill;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DecrementEconomicEventType getTypifiedBy() {
		if (typifiedBy != null && typifiedBy.eIsProxy()) {
			InternalEObject oldTypifiedBy = (InternalEObject)typifiedBy;
			typifiedBy = (DecrementEconomicEventType)eResolveProxy(oldTypifiedBy);
			if (typifiedBy != oldTypifiedBy) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, ReamodelPackage.DECREMENT_ECONOMIC_EVENT__TYPIFIED_BY, oldTypifiedBy, typifiedBy));
			}
		}
		return typifiedBy;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DecrementEconomicEventType basicGetTypifiedBy() {
		return typifiedBy;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTypifiedBy(DecrementEconomicEventType newTypifiedBy, NotificationChain msgs) {
		DecrementEconomicEventType oldTypifiedBy = typifiedBy;
		typifiedBy = newTypifiedBy;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ReamodelPackage.DECREMENT_ECONOMIC_EVENT__TYPIFIED_BY, oldTypifiedBy, newTypifiedBy);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTypifiedBy(DecrementEconomicEventType newTypifiedBy) {
		if (newTypifiedBy != typifiedBy) {
			NotificationChain msgs = null;
			if (typifiedBy != null)
				msgs = ((InternalEObject)typifiedBy).eInverseRemove(this, ReamodelPackage.DECREMENT_ECONOMIC_EVENT_TYPE__TYPIFY, DecrementEconomicEventType.class, msgs);
			if (newTypifiedBy != null)
				msgs = ((InternalEObject)newTypifiedBy).eInverseAdd(this, ReamodelPackage.DECREMENT_ECONOMIC_EVENT_TYPE__TYPIFY, DecrementEconomicEventType.class, msgs);
			msgs = basicSetTypifiedBy(newTypifiedBy, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ReamodelPackage.DECREMENT_ECONOMIC_EVENT__TYPIFIED_BY, newTypifiedBy, newTypifiedBy));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__OUTFLOW:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getOutflow()).basicAdd(otherEnd, msgs);
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__DUALITY:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getDuality()).basicAdd(otherEnd, msgs);
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__FULFILL:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getFulfill()).basicAdd(otherEnd, msgs);
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__TYPIFIED_BY:
				if (typifiedBy != null)
					msgs = ((InternalEObject)typifiedBy).eInverseRemove(this, ReamodelPackage.DECREMENT_ECONOMIC_EVENT_TYPE__TYPIFY, DecrementEconomicEventType.class, msgs);
				return basicSetTypifiedBy((DecrementEconomicEventType)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__OUTFLOW:
				return ((InternalEList<?>)getOutflow()).basicRemove(otherEnd, msgs);
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__DUALITY:
				return ((InternalEList<?>)getDuality()).basicRemove(otherEnd, msgs);
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__FULFILL:
				return ((InternalEList<?>)getFulfill()).basicRemove(otherEnd, msgs);
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__TYPIFIED_BY:
				return basicSetTypifiedBy(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__OUTFLOW:
				return getOutflow();
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__DUALITY:
				return getDuality();
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__FULFILL:
				return getFulfill();
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__TYPIFIED_BY:
				if (resolve) return getTypifiedBy();
				return basicGetTypifiedBy();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__OUTFLOW:
				getOutflow().clear();
				getOutflow().addAll((Collection<? extends Outflow>)newValue);
				return;
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__DUALITY:
				getDuality().clear();
				getDuality().addAll((Collection<? extends IncrementEconomicEvent>)newValue);
				return;
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__FULFILL:
				getFulfill().clear();
				getFulfill().addAll((Collection<? extends DecrementCommitment>)newValue);
				return;
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__TYPIFIED_BY:
				setTypifiedBy((DecrementEconomicEventType)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__OUTFLOW:
				getOutflow().clear();
				return;
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__DUALITY:
				getDuality().clear();
				return;
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__FULFILL:
				getFulfill().clear();
				return;
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__TYPIFIED_BY:
				setTypifiedBy((DecrementEconomicEventType)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__OUTFLOW:
				return outflow != null && !outflow.isEmpty();
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__DUALITY:
				return duality != null && !duality.isEmpty();
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__FULFILL:
				return fulfill != null && !fulfill.isEmpty();
			case ReamodelPackage.DECREMENT_ECONOMIC_EVENT__TYPIFIED_BY:
				return typifiedBy != null;
		}
		return super.eIsSet(featureID);
	}

} //DecrementEconomicEventImpl
